package com.wonders.hisdoctor.station.construct;

import com.wonders.his.common.utils.StringUtils;
import com.wonders.his.framework.utils.oracle.IdUtils;
import com.wonders.hisdoctor.station.enums.OracleSequenceEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 创建oracle数据库id序列化
 *
 * @author: tyang
 * date: 2020/12/9 9:19
 * @description: OracleSequenceConstruct
 */
@Component
public class OracleSequencePostConstruct {

    @Autowired
    private IdUtils idUtils;

    @Value("${seq.create.switch}")
    private Boolean seqCreateSwitch;

    @PostConstruct
    public void init() {
        if (seqCreateSwitch) {
            for (OracleSequenceEnum oracleSequenceEnum : OracleSequenceEnum.values()) {
                String seqName = oracleSequenceEnum.getCode();
                //序列是否存在,不存在就创建
                if (StringUtils.isEmpty(idUtils.getSequenceName(seqName))) {
                    idUtils.createSequence(seqName, oracleSequenceEnum.getStartWith());
                }
            }
        }
    }


}
